class StockLongJob
  include Sidekiq::Worker
  sidekiq_options :queue => :stock_long, :retry => false
  # 持仓股 job
  def perform(alert_message)
    if trade_time
      Stock.where(is_long: true).each do |stock|
        logger.info "is_long: #{stock.symbol} -- #{stock.name}"
        today = JSON.parse $Redis.get(stock["symbol"])
        content = <<~MD
        ** stock_choice_job ***
        > #{stock.symbol} -- #{stock.name}
        > 当前: #{today["trade"].to_f.round(2)}
        > 涨幅: #{today["changepercent"]}%
        > [编辑](https://wyyzrx.com/admin/stocks/#{stock.id}/edit)
        > 买入价: #{stock.buy_price} 
      MD

        # 如果当前价小于等于买入价
        if stock.buy_price.present? && today["trade"].to_f <= stock.buy_price.to_f
          content << <<~MD
            > 告警原因：低于目标价 #{stock.buy_price} 
        MD
          Time.now.day > 15 ? (Robot.dd_long_ai content) : (Robot.dd_long content)

        end
      end
    end
  end
end

